from selenium import webdriver
from lxml import etree
from urllib import request
import os
from datetime import datetime
import random

driver = webdriver.Chrome(executable_path=r"C:\Program Files\Python37\chromedriver.exe")
driver.get('https://image.baidu.com')

searchInput = driver.find_element_by_id('kw')
searchInput.send_key('街拍')

searchBtn = driver.find_element_by_class_name('s_search')
searchBtn.click()

img_list =[]
for index in range(0,600,100):
    html = driver.page_source
    parser = etree.HTML(html)
    temp_imgs = parser.xpath("//img[contains(@class,'main_img') and position() > %d]/@src"%len(img_list))
    img_list.extend(temp_imgs)
    driver.execute_script('window.scrollTo(0,%d'%index)

for index,img in enumerate(img_list):
    request.urlretrieve(img,os.path.join('images',str(index)+'.jpg'))
